<template>
  <div id="Premises">
<!--    //楼盘管理-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="">
        <el-input v-model="formInline.name" placeholder="楼盘名称/楼盘地址" />
      </el-form-item>
      <el-form-item label="">
        <el-select v-model="formInline.premisesType" placeholder="请选择物业类型">
          <el-option label="请选择物业类型" value="" />
          <el-option label="普通住宅" value="0" />
          <el-option label="公寓" value="1" />
          <el-option label="商住两用" value="2" />
          <el-option label="商业地产" value="3" />
          <el-option label="写字楼" value="4" />
        </el-select>
      </el-form-item>
      <el-form-item label="城市地区">
        <el-select v-model="formInline.province" clearable placeholder="请选择省" @change="Selectcity(formInline.province)">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.regionName"
            :value="item.regionId"
          />
        </el-select>
        <el-select v-model="formInline.city" clearable placeholder="请选择市" @change="SelectCount(formInline.city)">
          <el-option
            v-for="item in citys"
            :key="item.value"
            :label="item.regionName"
            :value="item.regionId"
          />
        </el-select>
        <el-select v-model="formInline.county" clearable placeholder="请选择县/区">
          <el-option
            v-for="item in counts"
            :key="item.value"
            :label="item.regionName"
            :value="item.regionId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
        <el-button @click="handleEdit">修改</el-button>
      </el-form-item>
    </el-form>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column
        prop="id"
        label="楼盘ID"
        width="120"
      />
      <el-table-column
        prop="name"
        label="楼盘名称"
        width="120"
      />
      <el-table-column
        label="楼盘图片"
        width="120"
      >
        暂无图片
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="120"
      />
      <el-table-column
        prop="premisesType"
        label="物业类型"
        width="120"
      >
        <template slot-scope="scope">
          <p v-if="scope.row.premisesType==0">普通住宅</p>
          <p v-else-if="scope.row.premisesType==1">公寓</p>
          <p v-else-if="scope.row.premisesType==2">商住两用</p>
          <p v-else-if="scope.row.premisesType==3">商业地产</p>
          <p v-else-if="scope.row.premisesType==4">写字楼</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="estate"
        label="物业管理公司"
        width="120"
      />
    </el-table>
    <el-pagination
      background
      :current-page="pageNum"
      :page-sizes="[10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      counts: [],
      options: [],
      citys: [],
      tableData: [],
      // 分页
      pageNum: 1,
      pageSize: 10,
      total: 0,
      // 查询
      formInline: {},
      regions: [],
      multipleSelection: []
    }
  },
  created() {
    this.initData()
    this.city()
  },
  methods: {
    city() {
      this.axios.get('http://localhost:9999/system-management/sysRegion/list', {
        params: {
          parentId: 1
        }
      }).then((response) => {
        this.options = response.data.obj
      })
    },
    Selectcity(val) {
      this.citys = []
      this.formInline.city = ''
      this.counts = []
      this.formInline.county = ''
      // 查询城市
      this.axios.get('http://localhost:9999/system-management/sysRegion/list', {
        params: {
          parentId: val
        }
      }).then((response) => {
        this.citys = response.data.obj
      })
    },
    SelectCount(val) {
      this.counts = []
      this.formInline.county = ''
      this.axios.get('http://localhost:9999/system-management/sysRegion/list', {
        params: {
          parentId: val
        }
      }).then((response) => {
        this.counts = response.data.obj
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.initData()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNum = val
      this.initData()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    initData() {
      this.axios.get('http://localhost:9999/house-market/tbPremisesInfo/list', {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          name: this.formInline.name,
          county: this.formInline.county,
          province: this.formInline.province,
          city: this.formInline.city
        }
      }).then((response) => {
        console.log(response.data)
        this.tableData = response.data.obj.list
        this.total = response.data.obj.total
      })
    },
    onSubmit() {
      console.log('submit!')
      this.initData()
    },
    handleEdit() {
      if (this.multipleSelection != null && this.multipleSelection.length > 0) {
        if (this.multipleSelection.length > 1) {
          alert('只能选择一名用户进行操作')
        } else {
          var id = this.multipleSelection[0].id
          this.$router.push({
            path: '/EditPremises',
            query: {
              pressesid: id
            }
          })
        }
      } else {
        alert('请选择一名用户进行操作')
      }
    }
  }
}
</script>
<style scoped>

</style>
